package com.woniuxy.woniuhis.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.woniuhis.entity.ExaminationItem;
import com.woniuxy.woniuhis.exception.ExaminationItemServiceException;
import com.woniuxy.woniuhis.mapper.ExaminationItemMapper;
import com.woniuxy.woniuhis.service.ExaminationItemService;

@Service
public class ExaminationItemServiceImpl implements ExaminationItemService{
	
	@Autowired
	ExaminationItemMapper examinationItemMapper;
	
	/**
	 * 	插入检查条目
	 */
	@Override
	public void addExaminationItem(ExaminationItem exItem) {
		try {
			examinationItemMapper.insertExaminationItem(exItem);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ExaminationItemServiceException(e.toString());
		}
	}
	/**
	 * 	根据检查条目id更新检查条目表的检查状态
	 */
	@Override
	public void modifyExaminationItemById(Boolean examStatus, String examItemId) {
		try {
			examinationItemMapper.updateExaminationItemById(examStatus, examItemId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ExaminationItemServiceException(e.toString());
		}
		
	}
	/**
	 * 	查询指定检查条目的信息,根据id
	 */
	@Override
	public ExaminationItem findExaminationItemById(String examItemId) {
		try {
			return examinationItemMapper.selectExaminationItemById(examItemId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ExaminationItemServiceException(e.toString());
		}
	}
	
	/**
	 *  根据检查单号查询所有的检查条目
	 */
	@Override
	public List<ExaminationItem> findAllExaminationItemsByExaminationId(String examinationId) {
		try {
			return examinationItemMapper.selectAllExaminationItemsByExaminationId(examinationId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ExaminationItemServiceException(e.toString());
		}
	}
	
	/**
	 *	条件查询，或者全部查询
	 */
	@Override
	public List<ExaminationItem> findAllExaminationItems(ExaminationItem item) {
		try {
			return examinationItemMapper.selectAllExaminationItems(item);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ExaminationItemServiceException(e.toString());
		}
	}
	@Override
	public PageInfo<ExaminationItem> findAllExaminationItems(ExaminationItem item, Integer page, Integer limit) {
		try {
			PageHelper.startPage(page, limit);
			List<ExaminationItem> examinationItems = examinationItemMapper.selectAllExaminationItems(item);
			PageInfo<ExaminationItem> pageInfo = new PageInfo<ExaminationItem>(examinationItems);
			return pageInfo;
		} catch (Exception e) {
			e.printStackTrace();
			throw new ExaminationItemServiceException(e.toString());
		}
	}

}
